package Queue;


import array.Array;

public class ArrayQueue<E> implements Queue<E>{

    private Array<E> array;

    public ArrayQueue(){
        this(5);
    }

    public ArrayQueue(int capacity){
        array = new Array(capacity);
    }

    @Override
    public void enqueue(E e) {
        array.addLast(e);
    }

    @Override
    public E dequeue() {
        return array.removeFirst();
    }

    @Override
    public E getFront() {
       return array.getFirst();
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public int getCapacity() {
        return array.getCapacity();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("ArrayQueue capacity:"+array.getCapacity()+"size:"+array.getSize()+",data:[");
        for (int i = 0; i < array.getSize(); i++) {
            sb.append(array.get(i));
            if(i != array.getSize() -1){
                sb.append(",");
            }
        }
        return sb.append("]").toString();
    }

    public static void main(String[] args) {
        ArrayQueue queue = new ArrayQueue<>(5);
        for (int i = 0; i < 5; i++) {
            queue.enqueue(i);
        }
        System.out.println(queue);
        queue.dequeue();
        System.out.println(queue);
        Object front = queue.getFront();
        System.out.println(front);

    }
}
